package controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import pojo.Hetong;
import pojo.User;
import pojo.Userlist;
import pojo.Zulist;
import service.UserlistService;
import service.ZulistService;

@Controller
@RequestMapping("/zulist")
public class ZulistController {
	@Autowired
	private ZulistService zulistService;
	@Autowired
	private UserlistService userlistService;

	// 跳到增添合同的页面
	@RequestMapping("/toaddhetong")
	public String toaddhetong(Model model, String house_id) {
		Hetong hetong = new Hetong();
		hetong.setHouse_id(house_id);
		model.addAttribute("hetong", hetong);
		model.addAttribute("mainPage", "addhetong.jsp");
		return "fangdong/main";
	}

	// 管理员查看所有在租列表
	@RequestMapping("/findzulist")
	public String findzulist(Model model, HttpSession httpSession,
			@RequestParam(required = false, defaultValue = "1") Integer page,
			@RequestParam(required = false, defaultValue = "3") Integer pageSize) throws Exception {
		User user1 = (User) httpSession.getAttribute("loginUser");
		PageHelper.startPage(page, pageSize);
		List<Zulist> zulist = zulistService.findzuuserlist(user1.getId());
		PageInfo<Zulist> p = new PageInfo<Zulist>(zulist);
		model.addAttribute("p", p);
		model.addAttribute("zulist", zulist);
		model.addAttribute("mainPage", "zulist.jsp");
		return "fangdong/main";
	}

	// 查看我的在租列表
	@RequestMapping("/myzulist")
	public String myzulist(Model model, HttpSession httpSession,
			@RequestParam(required = false, defaultValue = "1") Integer page,
			@RequestParam(required = false, defaultValue = "3") Integer pageSize) throws Exception {
		User user1 = (User) httpSession.getAttribute("loginUser");
		Userlist userlist = userlistService.findhasuserlist(user1.getId());
		PageHelper.startPage(page, pageSize);
		List<Userlist> list = userlistService.getUserzuList(userlist.getId());
		PageInfo<Userlist> p = new PageInfo<Userlist>(list);
		model.addAttribute("userlistzu", list);
		model.addAttribute("p", p);
		model.addAttribute("mainPage", "myzulist.jsp");

		return "zuke/main";
	}

}
